package com.frxuexi.shop.viewmodel

import com.frxuexi.lib_base.http.ShopApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import com.frxuexi.shop.intent.CartIntent
import com.frxuexi.shop.intent.ShopIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class CartViewModel @Inject constructor(val shopApiService: ShopApiService):BaseViewModel<CartIntent>() {
    override fun handlerIntent(it: CartIntent) {
        when(it){
            is CartIntent.getCarts->httpRequest(shopApiService.getCarts(it.page))
            is CartIntent.updateCart->httpRequest(shopApiService.updateCart(it.id,it.number),RequestType.UPDATE)
            is CartIntent.preOrder->httpRequest(shopApiService.preOrder(toBody(it.item)),RequestType.ADD)
            is CartIntent.loadPreOrder->httpRequest(shopApiService.getPreOrder(it.orderNo),RequestType.GETPRE_ORDER)
            is CartIntent.createOrder->httpRequest(shopApiService.createOrder(toBody(it.item)),RequestType.CREATE)
            is CartIntent.payOrder->httpRequest(shopApiService.payOrder(toBody(it.map)),RequestType.PAY)
        }

    }
}